package controller;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.json.JSONArray;

import model.Empresa;


import dao.ConnectionFactory;
import dao.FuncionarioDao;

@Path("/funcionario")
public class FuncionarioServices {

	private Connection connection;
	
	public FuncionarioServices(){
		this.connection = new ConnectionFactory().getConnection();
	}
	
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public ArrayList<model.Funcionario> listar(@QueryParam("idEmpresa") long idEmpresa){
	
	  this.connection = new ConnectionFactory().getConnection();
	  
	  Empresa empresa = new Empresa();
	  empresa.setIdEmpresa(idEmpresa);
	  FuncionarioDao funcDao = new FuncionarioDao(connection);
	  
	  ArrayList<model.Funcionario> listaFuncionarios = funcDao.listarFuncionarios(empresa);
		
	  try {	this.connection.close(); } catch (SQLException e) {	 e.printStackTrace(); }
	  
	  return listaFuncionarios;
	}
	
	
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  public void cadastrar(@QueryParam("nmFuncionario") String nmFuncionario, @QueryParam("idEmpresa")long idEmpresa, @QueryParam("idDepartamento") long idDepartamento){
	  
	  this.connection = new ConnectionFactory().getConnection();
	  
	  
	  
	  try {	this.connection.close(); } catch (SQLException e) {	 e.printStackTrace(); }
  }
  
	
  @POST
  public void atualizar(@QueryParam("id") long id){
  
  }
  
  
  @DELETE
  public void exlcuir(@QueryParam("id") long id){
	  
  }
  
  
  
}
